#!/bin/sh
#
# Copyright (c) 2013 Jeffrey M. Squyres.  All rights reserved.
#
# $COPYRIGHT$
#
# Additional copyrights may follow
# 
# $HEADER$
#
# Put this script in /etc/network/if-up.d/rubyslippers to
# auto-launch ruby slippers when the network interface
# comes up.
#

# Don't bother to restart ruby slippers when lo is configured.
if [ "$IFACE" = lo ]; then
	exit 0
fi

# Make sure this is an ipv4 interface
if [ "$ADDRFAM" != inet ]; then
	exit 0
fi

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/home/pi/git/pynest

. /lib/lsb/init-functions

BIN=/home/pi/git/rubyslippers/rubyslippers.pl
PIDFILE=/var/run/rubyslippers

do_start () {
	cd $HOME
	log_daemon_msg "Starting Ruby Slippers" "rubyslippers"
	start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --exec $BIN -- --no-debug --config /home/pi/.rubyslippers.config 
	log_end_msg $?
}

do_stop () {
	log_daemon_msg "Stopping Ruby Slippers" "rubyslippers"
  	start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
	log_end_msg $?
	rm -f $PIDFILE
}

case "$MODE" in
  start|"")
	do_start
	;;
  stop)
	do_stop
	;;
  *)
	echo "Unknown mode"
	exit 3
	;;
esac


